package com.jiangds.open.check.spring;

import com.jiangds.open.check.Check;
import com.jiangds.open.check.processor.DefaultSingleProcessor;
import com.jiangds.open.check.spring.aop.CheckAdvisor;
import com.jiangds.open.check.spring.aop.CheckHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * {@link AutoCheckConfiguration}  自动配置类
 *
 * @author jiangliang
 * @since 2021/1/8 13:29
 */
@Configuration
@EnableConfigurationProperties(CheckProperties.class)
@ConditionalOnProperty(name = "check.package-name")
public class AutoCheckConfiguration {

    @Autowired
    private CheckProperties checkProperties;

    @Bean
    @ConditionalOnMissingBean
    public Check check(){
        return new Check(DefaultSingleProcessor.getInstance());
    }

    @Bean
    @ConditionalOnMissingBean
    public CheckHandler checkHandler(Check check){
        return new CheckHandler(check);
    }

    @Bean
    @ConditionalOnMissingBean
    public CheckAdvisor checkAdvisor(CheckHandler checkHandler){
        return new CheckAdvisor(checkProperties,checkHandler);
    }

}
